const { ccclass, property } = cc._decorator;

@ccclass
export default class RandomSprite extends cc.Component {

    @property([cc.SpriteFrame])
    spriteArr: cc.SpriteFrame[] = [];

    start() {
        this.randomizeSprite();
    }

    randomizeSprite() {
        let sprite = this.node.getComponent(cc.Sprite);
        if (sprite && this.spriteArr.length > 0) {
            let randomIndex = Math.floor(Math.random() * this.spriteArr.length);
            sprite.spriteFrame = this.spriteArr[randomIndex];
        }
    }
}